<div class="search-bar">
    <ul>
        <li>单据状态：</li>
        <li>
            <select id="status" class="province floatleft select1">
                <option value="-1" selected="selected">全部</option>
                <option value="1">待处理</option>
                <option value="3">成功</option>
                <option value="4">失败</option>
            </select>
        </li>
        
        <li class="marginleft10">起止日期：</li>
        <li>
            <input id="startDate"> ~ 
            <input id="endDate">
        </li>
        
        <li>
            <button type="button" class="btn" >搜索</button>
        </li>
        <div class="clear"></div>
    </ul>
</div>

<div class="records">
    <table class="table">
        <thead>
            <tr class="trcolor">
                <th style="width: 10%">时间</th>
                <th style="width: 6%">交易类型</th>
                <th style="width: 6%">金额</th>
                <th style="width: 28%">交易描述</th>
                <th style="width: 12%">单据状态</th>
                <th style="width: 6%">详情</th>
            </tr>
        </thead>
        <tbody id="withdrawlist-tbody"><tr class="trcolor"><td colspan="6">暂无数据</td></tr></tbody>
    </table>
</div>

<div class="page_info">
    <div id="listPage" class="megas512 zxf_pagediv"></div>    
</div>
<div style="height:50px;"></div>

<script>
    (function() {
        $("#startDate").datepicker({format: 'yyyy-mm-dd'});
        $("#endDate").datepicker({format: 'yyyy-mm-dd'});

        $("#status").change(function() {
            Page.currPage = 1;
            queryChargeLogList(1);
        })

        var Page = new PageList();
        Page.pageSize = 15;
        Page.denyTrai = true;
        Page.jumpPage = function(page) {
            queryChargeLogList(page);
        }
        $(".search-bar .btn").click(function() {
            queryChargeLogList(1);
        });

        function queryChargeLogList(page) {
            var data = {
                owner: "",
                type: "withdraw",
                pageSize: Page.getPageSize(),
                pageNum: page || 1,
            };
            Page.currPage = page || 1;
            if ($("#status").val() != '-1') data.state = $("#status").val();
            if ($("#startDate").val() != '') data.start = $("#startDate").val().trim();
            if ($("#endDate").val() != '') data.end = $("#endDate").val().trim();
            startLoading();
            CMD.query_account_log2(data, function(r) {
                stopLoading();
                Page.fillPages(r.count, r.number, r.page, r.size);
                fillChargeLogList(r.list);
            });
        }
        queryChargeLogList(1);

        function fillChargeLogList(list) {
            var table = $("#withdrawlist-tbody"); table.empty();
            var count = 0;
            for (var i in list) {
                var d = list[i];
                if (count % 2 == 0)
                    var tr = $("<tr class='trcolor'></tr>");
                else
                    var tr = $("<tr></tr>");
                count++;

                tr.append('<td>' + d.start + '</td>');
                tr.append('<td>取款</td>');
                tr.append('<td>' + d.amount/100 + '</td>');

                // 交易描述
                var s = "申请提款__v__元";
                s = s.replace(/__c__/, Util.convertChannel(d.channel));
                s = s.replace(/__v__/, d.amount/100);
                tr.append('<td>' + s + '</td>');
                if (d.state == 0) tr.append('<td>处理中</td>');
                else if (d.state == 1) tr.append('<td>成功</td>');
                else if (d.state == 2) tr.append('<td>失败</td>');

                // 详情
                var l = '<a href="#" value="__v__">详情</a>'.replace(/__v__/, d.id);
                tr.append('<td>' + l + '</td>');
                table.append(tr);
            }
            if (Util.isEmpty(list)) {
                table.append("<tr><td colspan='6'>暂无数据</td></tr>");
                return;
            }

            $("#withdrawlist-tbody a").click(function(e) {
                var id = $(e.currentTarget).attr("value");
                for (var i in list) {
                    if (list[i].id != id) continue;

                    // 弹出详情
                    popChargeDetail(list[i]);
                    break;
                }
            });
        }

        function popChargeDetail(data) {
            var str = '<div class="pop-detail">\
					<p>交易编号：__no__</p>\
					<p>发起时间：__t__</p>\
					<p>交易类型：提款 </p>\
					<p>交易金额：__amount__</p>\
					<p>活动奖励金额：0</p>\
					<p>手续费用：0</p>\
					<p>交易状态：__state__ </p>\
					<p>审核时间：__t2__</p>';
            str = str.replace(/__no__/, data.id);
            str = str.replace(/__t__/, data.start);
            str = str.replace(/__t2__/, data.end || '');
            str = str.replace(/__amount__/, data.amount/100);
            if (data.state == 0)
                str = str.replace(/__state__/, "等待审核");
            if (data.state == 1)
                str = str.replace(/__state__/, "提款成功");
            if (data.state == 2)
                str = str.replace(/__state__/, "提款失败");
            var memo = {};
            try {
                memo = JSON.parse(data.memo || '{}');
            } catch(e) {}
            if (data.state == 2 && memo.reason) {
                str += '<p>驳回原因：' + memo.reason + '</p>';
            }
            str += '</div>';

            layer.open({
                type : 1,
                title : '提款详情',
                scrollbar : false,
                shade : [ 0.5 ],
                area : [ '500px', '360px' ],
                content : str
            });
            $(".layui-layer-content").css("height", "auto");
            $(function() {
                $("body").resize();
                setTimeout(function() {
                    $("body").resize();
                }, 150);
            })
        }
    })();
</script>